package com.xbongbong.workflow.service.field.impl;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.util.LinkDataUtil;
import com.xbongbong.workflow.domain.entity.WorkflowNodeEntity;
import com.xbongbong.workflow.pojo.FilterCondition;
import com.xbongbong.workflow.pojo.WorkflowRulePojo;
import com.xbongbong.workflow.service.field.AbstractWorkflowConditionFieldService;
import com.xbongbong.workflow.service.field.WorkflowConditionFieldService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author 吴峰
 * @date 2021/06/07 14:03
 */
@Service("workflowConditionLinkBusinessServiceImpl")
public class WorkflowConditionLinkBusinessServiceImpl extends AbstractWorkflowConditionFieldService implements WorkflowConditionFieldService {


    @Override
    public List<Integer> fieldType() {
        return Arrays.asList(FieldTypeEnum.LINK_BUSINESS_SINGLE.getType());
    }

    @Override
    public Object handlerThisFormField(PaasFormDataEntityExt paasFormDataEntity, JSONObject data, FieldAttrEntity fieldAttrEntity, FieldAttrEntity targetField, WorkflowNodeEntity workflowNodeEntity, FilterCondition filterCondition, WorkflowRulePojo workflowRulePojo) throws XbbException {
        return data.get(fieldAttrEntity.getAttr());
    }

    @Override
    public Object handlerTargetFormField(Object object, PaasFormDataEntityExt paasFormDataEntity, JSONObject data, FieldAttrEntity fieldAttrEntity, FieldAttrEntity targetField, WorkflowNodeEntity workflowNodeEntity, WorkflowRulePojo workflowRulePojo, FilterCondition filterCondition) throws XbbException {
        return LinkDataUtil.getIdByLinkBusiness(object);
    }
}
